package com.thiswhyme.seata.order.controller;

import com.thiswhyme.common.response.ResponseCode;
import com.thiswhyme.common.response.ResponseVo;
import com.thiswhyme.seata.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: thiswhyme
 * @date: 2020/9/4
 */
@RestController
@RequestMapping("/order/")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("placeOrder")
    public ResponseVo<Boolean> placeOrder(@RequestParam Long userId, @RequestParam Long productId, @RequestParam Integer price) {
        try {
            orderService.placeOrder(userId, productId, price);
            return ResponseVo.success();
        } catch (Exception e) {
            return ResponseVo.failure(ResponseCode.SYSTEM_EXCEPTION.getCode(), e.getMessage());
        }
    }
}
